package PhienBanNIO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ReadAndQWrite {
	public static void main(String [] args){
		try {
			FileInputStream fin = new FileInputStream("D:\\a.txt");
			FileChannel fic = fin.getChannel();
			ByteBuffer buffer = ByteBuffer.allocate(1024);
			
			FileOutputStream fout = new FileOutputStream("D:\\out.txt");
			FileChannel fc = fout.getChannel();
			while(true){
				if(fic.read(buffer)==-1)
						break;
				buffer.flip();
				fc.write(buffer);
				buffer.clear();
			}
			
			
			fic.close();
			fc.close();
			fin.close();
			fout.close();
		} catch (FileNotFoundException e) {
			System.out.println("Khong tim thay file");
			}
		catch(IOException e){
			
		}
		catch(NullPointerException e){
			
		}
	}

}
